package com.kk.xhr.web.request;

import com.kk.xhr.common.Constants;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * 分页查询请求。
 *
 * @author Zhen Wang
 * @version 1.0
 * @since 1.0.0
 */
@ApiModel
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PagedRequest {
    /** 起始位置 */
    @ApiModelProperty(value = "起始位置", notes = "采用倒序排列，不传从最新的开始", example = "0")
    @Max(10000)
    @Min(0)
    private Integer offset = Constants.ZERO;
    /** 最大返回数据量 */
    @ApiModelProperty(value = "最大返回数据量", notes = "默认20", example = "20")
    @Max(100)
    @Min(1)
    private Integer limit = Constants.DEFAULT_LIMIT;

    public void setOffset(Integer offset) {
        if (null == offset) {
            offset = 0;
        }
        this.offset = offset;
    }

    public void setLimit(Integer limit) {
        if (null == limit) {
            limit = Constants.DEFAULT_LIMIT;
        }
        this.limit = limit;
    }
}
